package org.frasermccrossan.toneitdown;

import android.content.Context;
import android.media.AudioManager;

class Profile {
	long _id;
	String name;
	int volume;
	int vibrate;
	
	Profile(String name, int volume, int vibrate) {
		this.name = name;
		this.volume = volume;
		this.vibrate = vibrate;
	}
	
	Profile(long _id, String name, int volume, int vibrate) {
		this._id = _id;
		this.name = name;
		this.volume = volume;
		this.vibrate = vibrate;
	}
	
	void apply(Context c, boolean showUI) {
		AudioManager am = (AudioManager) c.getSystemService(Context.AUDIO_SERVICE);
		setVibrate(am, AudioManager.VIBRATE_TYPE_RINGER);
		setVibrate(am, AudioManager.VIBRATE_TYPE_NOTIFICATION);
		setVolume(am, AudioManager.STREAM_RING, showUI ? AudioManager.FLAG_SHOW_UI : 0);
		setVolume(am, AudioManager.STREAM_NOTIFICATION, 0);
	}

	private void setVolume(AudioManager am, int streamType, int flags) {
    	am.setStreamVolume(streamType, volume, flags);
    }
	
	private void setVibrate(AudioManager am, int vibrateType) {
		am.setVibrateSetting(vibrateType, vibrate > 0 ? AudioManager.VIBRATE_SETTING_ON : AudioManager.VIBRATE_SETTING_OFF);
	}
}
